package com.cs;

import org.springframework.boot.web.servlet.error.ErrorController;
import org.springframework.validation.BindException;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.jws.WebResult;
import javax.servlet.http.HttpServletResponse;

@RestControllerAdvice
public class GlobalException implements ErrorController {

    @ResponseBody
    @ExceptionHandler(BindException.class)
    public String globalException(HttpServletResponse response, BindException ex){
        String s = ex.getFieldError().getDefaultMessage();
        return s;
    }
}
